﻿var entryEditor = null;
var commentEditor = null

$(function () {
    //Init the CKEditor
    initRichText();
});

/// Instanciate CE Editors
function initRichText() {
    //Create the text editor for new entry
    if (document.getElementById('Content') !== null) {
        entryEditor = CKEDITOR.replace('Content', CKEFull);
        //Thing to do when instance created
        entryEditor.on('instanceReady', function (e) {
            validateNewEntry();
        })
    }

    //Create the text editor for comment
    if (document.getElementById('NewComment') !== null) {
        commentEditor = CKEDITOR.replace('NewComment', CKEMini);
        //Thing to do when instance created
        commentEditor.on('instanceReady', function (e) {
            validateNewComment();
        })
    }
}

/// Form input validation
function validateNewEntry() {
    //Submit
    $(':submit').each(function () {
        $(this).click(function (e) {
            //Publish
            if ($(this).attr('value') == 'Publish') {
                //Empty title
                if (!ValidateRequired($('#Title'))) {
                    e.preventDefault();
                }
                else {
                    if (IsEditorEmpty($('#Content'))) {
                        if (!confirm('The entry body is empty!\r\n\r\nAre you sure?')) {
                            e.preventDefault();
                        }
                    }
                }
            }
        });
    });
}

function validateNewComment() {
}